import React from 'react';

import {BrowserRouter as Router,Route,Switch,Link} from 'react-router-dom';
import Bundle from './bundle';
// import Home from 'bundle-loader?lazy&name=home!pages/home.js';
// import Nofound from 'bundle-loader?lazy&name=404!pages/404.js';
// import Detail from 'bundle-loader?lazy&name=detail!pages/detail.js';
// import Login from 'bundle-loader?lazy&name=login!pages/login.js';
// import Postlist from 'bundle-loader?lazy&name=postlist!pages/postlist.js';
// import Editor from 'bundle-loader?lazy&name=editor!pages/editor.js';
// import Register from 'bundle-loader?lazy&name=register!pages/register.js';
// import PersonalCentral from 'bundle-loader?lazy&name=personal!pages/personalCentral.js';
// import Dialog from 'bundle-loader?lazy&name=dialog!module/dialog/example.js';
import Home from './pages/home.js';
import Nofound from './pages/404.js';
import Detail from './pages/detail.js';
import Login from './pages/login.js';
import Postlist from './pages/postlist.js';
import Editor from './pages/editor.js';
import Register from './pages/register.js';
import PersonalCentral from './pages/personalCentral.js';
import Dialog from './module/dialog/example.js';



const Loading = function () {
	return <div>Loading...</div>
}

const createComponent = (component) => () => (
	<Bundle load={component}>{
		(Component) => Component ? <Component/> : <Loading/>
	}</Bundle>
);

const getRouter=() => {
	<Router>
		<Switch>
			<Route exact path="/" component={createComponent(Home)}></Route>
       		<Route path="/home" component={createComponent(Home)}></Route>
        	<Route path="/404" component={createComponent(Nofound)}></Route>
        	<Route path="/detail" component={createComponent(Detail)}></Route>
        	<Route path="/login" component={createComponent(Login)}></Route>
        	<Route path="/postlist" component={createComponent(Postlist)}></Route>
        	<Route path="/editor" component={createComponent(Editor)}></Route>
        	<Route path="/Register" component={createComponent(Register)}></Route>
        	<Route path="/personal" component={createComponent(PersonalCentral)}></Route>
        	<Route path="/dialog" component={createComponent(Dialog)} ></Route>
        </Switch>	
	</Router>
}

export default getRouter;